package com.sc.service.impl.vehicle;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.domain.VehicleRegion;
import com.sc.dto.VehicleRegionNamePageDTO;
import com.sc.mapper.vehicle.VehicleRegionMapper;
import com.sc.service.vehicle.IVehicleRegionService;
import org.springframework.stereotype.Service;


@Service
public class IVehicleRegionServiceImpl extends ServiceImpl<VehicleRegionMapper,VehicleRegion> implements IVehicleRegionService {


    /**
     * 添加一个区域
     * @param vehicleRegion
     * @return
     */
    @Override
    public Boolean addVehicleRegion(VehicleRegion vehicleRegion) {
        boolean isSuccess = saveOrUpdate(vehicleRegion);
        return isSuccess;
    }

    /**
     * 查询区域列表
     * @return
     */
    @Override
    public Page<VehicleRegion> showRegions(Integer pageNum, Integer pageSize) {
        Page<VehicleRegion> page = Page.of(pageNum,pageSize);
        page(page);
        return page;
    }
    /**
     * 查询区域详情
     * @return
     */
    @Override
    public VehicleRegion getRegionById(Integer id) {
        VehicleRegion region = getById(id);
        return region;
    }

    @Override
    public Boolean deleteVehicleRegion(Integer id) {
        boolean b = removeById(id);
        return b;
    }

    @Override
    public Page<VehicleRegion> PageQueryByRegionName(VehicleRegionNamePageDTO regionNamePageDTO) {
        Page<VehicleRegion> page = Page.of(regionNamePageDTO.getPageNum(), regionNamePageDTO.getPageSize());
        QueryWrapper<VehicleRegion> wrapper = new QueryWrapper<>();
        if (regionNamePageDTO.getName() != null)
        {
            wrapper.like("name",regionNamePageDTO.getName())
                    .or()
                    .like("no",regionNamePageDTO.getName());
        }
        page(page,wrapper);
        return page;
    }


}
